package com.forlove.app.qselect.login.entity;

import com.forlove.app.ForloveApplication;
import com.forlove.app.common.base.mvp.entity.BaseEntity;
import com.forlove.app.common.base.serializer.JSONKey;
import com.forlove.app.common.utils.StringUtils;
import com.forlove.app.common.utils.SystemUtils;
import com.forlove.app.manager.UserManager;

/**
 * 用户登陆的entity
 * Created by yjl on 2017/9/27.
 */

public class UserEntity extends BaseEntity {

    @JSONKey(type = Integer.class, keys = "user_id")
    public int userId;  //用户id

    @JSONKey(keys = "img", type = String.class)
    public String mUserImage; //用户头像

    @JSONKey(keys = "username", type = String.class)
    public String userName; //用户姓名

    @JSONKey(type = String.class, keys = "username_fc")
    public String username_fc;

    @JSONKey(keys = "realname", type = String.class)
    public String realname;

    @JSONKey(type = String.class, keys = "realname_fc")
    public String realname_fc;


    @JSONKey(keys = "mobile", type = String.class)
    public String userMobile; //用户电话

    @JSONKey(type = String.class, keys = "access_token")
    public String access_token;

    @JSONKey(type = String.class, keys = "device_no")
    public String device_no = SystemUtils.getUserDeviceID();

    @JSONKey(keys = "mobile_type", type = String.class)
    public String mobile_type = "android";

    @JSONKey(type = String.class, keys = "password")
    public String password; //md5后的

    @JSONKey(keys = "note_times", type = Integer.class)
    public int note_times = 0;  //被圈次数

    @JSONKey(keys = "answer_times", type = Integer.class)
    public int answer_times = 0;  //答题数

    @JSONKey(keys = "isfriend", type = Boolean.class)
    public boolean isfriend;

    @JSONKey(keys = "friends_count", type = Integer.class)
    public int friends_count = 0;

    @JSONKey(keys = "lastloc", type = String.class)
    public String lastloc; //经纬度

    @JSONKey(type = Integer.class, keys = "sex")
    public int mSex;  //性别1男， 2女

    @JSONKey(keys = "issingle", type = Integer.class)
    public int issingle; //是否单身

    @JSONKey(keys = "scholar", type = Integer.class)
    public int scholar; //年级,学生

    @JSONKey(keys = "birthday", type = String.class)
    public String birthday;

    @JSONKey(keys = "group_tag", type = Integer.class)
    public int group_tag;

    @JSONKey(keys = "address", type = Integer.class)
    public int address;

    @JSONKey(type = String.class, keys = "regId")
    public String regId = UserManager.getJPushID(ForloveApplication.getInstance());

    @JSONKey(keys = "charm", type = Integer.class)
    public int charm;//魅力值

    @JSONKey(keys = "school", type = Integer.class)
    public int school; //学校

    @JSONKey(keys = "yuanxi", type = String.class)
    public String yuanxi;//院系

    @JSONKey(keys = "diamond", type = Integer.class)
    public int diamond;  //宝石数目

    public UserEntity() {
    }

    public UserEntity(int userId, String userName, String userMobile, String access_token, String password) {
        this.userId = userId;
        this.userName = userName;
        this.userMobile = userMobile;
        this.access_token = access_token;
        this.password = password;
    }

    /**
     * 更新用户信息，不更新accesstoken
     *
     * @param userEntity
     */
    public void updateUserEntity(UserEntity userEntity) {
        this.userId = userEntity.userId;
        this.mUserImage = userEntity.mUserImage;
        this.userName = userEntity.userName;
        this.username_fc = userEntity.username_fc;
        this.realname = userEntity.realname;
        this.realname_fc = userEntity.realname_fc;
        this.userMobile = userEntity.userMobile;
//        this.access_token = userEntity.access_token;
        this.device_no = userEntity.device_no;
        this.mobile_type = userEntity.mobile_type;
        this.password = userEntity.password;
        this.note_times = userEntity.note_times;
        this.answer_times = userEntity.answer_times;
        this.isfriend = userEntity.isfriend;
        this.friends_count = userEntity.friends_count;
        this.lastloc = userEntity.lastloc;
        this.mSex = userEntity.mSex;
        this.issingle = userEntity.issingle;
        this.scholar = userEntity.scholar;
        this.birthday = userEntity.birthday;
        this.group_tag = userEntity.group_tag;
        this.address = userEntity.address;
        this.regId = userEntity.regId;
        this.charm = userEntity.charm;
        this.school = userEntity.school;
        this.yuanxi = userEntity.yuanxi;
    }

    /**
     * 判断是否是同一个用户，只根据User id 判断
     *
     * @param model
     * @return
     */
    public boolean isSameUser(UserEntity model) {
        if (model == null && model.userId == 0) {
            return false;
        }
        if (model.userId > 0 && this.userId == model.userId) {
            return true;
        }
        return false;
    }


    /**
     * 返回可以显示的名称
     *
     * @return
     */
    public String getAvailableName() {
        if (StringUtils.isNotEmpty(this.realname)) {
            return this.realname;
        } else if (StringUtils.isNotEmpty(this.userName)) {
            return this.userName;
        } else {
            return "圈一圈用户";
        }
    }


}
